package com.tzy.for10evalue.utils.localcache;

import com.google.common.base.Optional;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author tzy
 * @date 2022/3/21 16:07
 */
public class BusinessCache {

    /**
     * 缓存
     */
    public static LoadingCache<String, Optional<List<String>>> oneCache = CacheBuilder
            .newBuilder()
            .expireAfterWrite(60, TimeUnit.MINUTES)
            .recordStats()
            .build(
                    new CacheLoader<String, Optional<List<String>>>() {
                        @Override
                        public Optional<List<String>> load(String key) throws Exception {
                            return Optional.fromNullable(null);
                        }
                    }
            );

    /**
     * Optional<Object> object是统一接口返回类
     * 缓存
     */
    public static LoadingCache<String, Optional<Object>> categoryCache = CacheBuilder
            .newBuilder()
            .expireAfterWrite(20, TimeUnit.MINUTES)
            .recordStats()
            .maximumSize(2000)
            .build(
                    new CacheLoader<String, Optional<Object>>() {
                        @Override
                        public Optional<Object> load(String key) throws Exception {
                            return Optional.fromNullable(null);
                        }
                    }
            );

    /**
     *  Object为PlZoneLabelDto
     */
    public static String zoneLabelPre = "zonelabel-";
    public static LoadingCache<String, Optional<Object>> zoneLabelCache = CacheBuilder
            .newBuilder()
            .expireAfterWrite(2, TimeUnit.HOURS)
            .recordStats()
            .maximumSize(10000)
            .build(
                    new CacheLoader<String, Optional<Object>>() {
                        @Override
                        public Optional<Object> load(String key) throws Exception {
                            return Optional.fromNullable(null);
                        }
                    }
            );




    public static String pagePre = "page-";
    public static LoadingCache<String, Optional<String>> pageCache = CacheBuilder
            .newBuilder()
            .expireAfterWrite(10, TimeUnit.MINUTES)
            .recordStats()
            .maximumSize(50)
            .build(
                    new CacheLoader<String, Optional<String>>() {
                        @Override
                        public Optional<String> load(String key) throws Exception {
                            return Optional.fromNullable(null);
                        }
                    }
            );

}
